﻿package mortal.game.view.task.view.base
{
    import com.gengine.core.*;
    import com.gengine.global.*;
    import com.gengine.utils.*;
    import com.greensock.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import mortal.component.window.resWin.*;
    import mortal.game.manager.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.map3D.*;
    import mortal.game.view.common.*;
    import mortal.game.view.task.view.track.*;

    public class TaskViewBase extends ResView
    {
        private var _bodySprite:ResBasePanel;
        protected var _bgSprite:ResBasePanel;
        protected var _bgImg:Bitmap;
        private var _moveBtn:GLoadedButton;
        private var _btnShowTrack:BtnShowTrackModule;
        private var _dragRect:Rectangle;
        protected var _judgeRec:Rectangle;
        private var _tween:TweenMax;
        private var _isClose:Boolean = false;
        protected var contentPanel:TaskViewContentPanel;

        public function TaskViewBase(param1:String = null)
        {
            this._dragRect = new Rectangle();
            this._judgeRec = new Rectangle(0, 0, 208, 220);
            super(param1);
            this.layer = LayerManager.uiLayer;
            mouseEnabled = false;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            if (this._tween != null && this._tween.active)
            {
                this._tween.kill();
                this._tween = null;
            }
            StageMouseManager.instance.removeRecEvent(this._judgeRec);
            if (this._bodySprite != null)
            {
                this._bodySprite.dispose(param1);
                this._bodySprite = null;
            }
            this._bgSprite = this._bgSprite && this._bgSprite.dispose(param1) ? (null) : (null);
            if (this._bgImg && this._bgImg is IDispose)
            {
                IDispose(this._bgImg).dispose(param1);
            }
            this._bgImg = null;
            this._moveBtn = this._moveBtn && this._moveBtn.dispose(param1) ? (null) : (null);
            this._btnShowTrack = this._btnShowTrack && this._btnShowTrack.dispose(param1) ? (null) : (null);
            this._bodySprite = this._bodySprite && this._bodySprite.dispose(param1) ? (null) : (null);
            return;
        }// end function

        override public function layoutUI() : void
        {
            super.layoutUI();
            this._bodySprite = UICompomentPool.getUICompoment(ResBasePanel) as ResBasePanel;
            addChild(this._bodySprite);
            this._bodySprite.mouseEnabled = false;
            this._bgSprite = UICompomentPool.getUICompoment(ResBasePanel) as ResBasePanel;
            this._bodySprite.addChild(this._bgSprite);
            this._bgSprite.mouseEnabled = false;
            this._bgSprite.mouseChildren = false;
            this._bgImg = this.CreateBg();
            this._bgImg.width = 208;
            this._moveBtn = UIFactory.gLoadedButton(ImagesConst.TaskTrackMove_upSkin, 0, 3, 18, 18, this._bodySprite);
            this._moveBtn.toolTipData = HTMLUtil.addColor(Language.getString(20143), "#FFFFFF");
            this._btnShowTrack = UICompomentPool.getUICompoment(BtnShowTrackModule) as BtnShowTrackModule;
            this._btnShowTrack.width = 18;
            this._btnShowTrack.height = 18;
            this._btnShowTrack.x = 189;
            this._btnShowTrack.y = 3;
            this.addChild(this._btnShowTrack);
            this._moveBtn.configEventListener(MouseEvent.MOUSE_DOWN, this.onMoveBtnMouseHandler);
            this._btnShowTrack.configEventListener(MouseEvent.CLICK, this.showHideTrackHandler);
            StageMouseManager.instance.addRecEvent(this._judgeRec, this.mouseOverModuleHandler, this.mouseOutModuleHandler);
            return;
        }// end function

        private function onMoveBtnMouseHandler(event:MouseEvent) : void
        {
            this._dragRect.x = 0;
            this._dragRect.y = 0;
            this._dragRect.width = SceneRange.display.width - 30;
            this._dragRect.height = SceneRange.display.height - 30;
            startDrag(false, this._dragRect);
            Global.stage.addEventListener(MouseEvent.MOUSE_UP, this.onStageMouseUpHandler);
            return;
        }// end function

        private function onStageMouseUpHandler(event:MouseEvent) : void
        {
            this.updateJudgeRect();
            stopDrag();
            Global.stage.removeEventListener(MouseEvent.MOUSE_UP, this.onStageMouseUpHandler);
            return;
        }// end function

        public function showHideTrackHandler(event:MouseEvent = null) : void
        {
            this.isClose = this._btnShowTrack.isClose;
            this.refresh();
            return;
        }// end function

        public function get isClose() : Boolean
        {
            return this._isClose;
        }// end function

        public function set isClose(param1:Boolean) : void
        {
            this._isClose = param1;
            return;
        }// end function

        private function open() : void
        {
            var _loc_1:Boolean = true;
            this._btnShowTrack.open();
            this._bodySprite.visible = _loc_1;
            if (this.contentPanel)
            {
                this.contentPanel.visible = _loc_1;
            }
            return;
        }// end function

        private function close() : void
        {
            var _loc_1:Boolean = false;
            this._btnShowTrack.close();
            this._bodySprite.visible = _loc_1;
            if (this.contentPanel)
            {
                this.contentPanel.visible = _loc_1;
            }
            return;
        }// end function

        protected function mouseOverModuleHandler() : void
        {
            this.killTween();
            this._tween = TweenMax.to(this, 0.3, {trackAlpha:1});
            return;
        }// end function

        protected function mouseOutModuleHandler() : void
        {
            this.killTween();
            this._tween = TweenMax.to(this, 6, {trackAlpha:0});
            return;
        }// end function

        public function set trackAlpha(param1:Number) : void
        {
            if (this._btnShowTrack && this._bodySprite)
            {
                this._btnShowTrack.alpha = param1;
                this._bodySprite.alpha = param1;
            }
            if (this.contentPanel && this.contentPanel.titleLabel)
            {
                this.contentPanel.titleLabel.alpha = param1;
            }
            return;
        }// end function

        public function get trackAlpha() : Number
        {
            if (this._bodySprite == null)
            {
                return 0;
            }
            return this._bodySprite.alpha;
        }// end function

        protected function killTween() : void
        {
            if (this._tween)
            {
                this._tween.kill();
            }
            return;
        }// end function

        override public function stageResize() : void
        {
            super.stageResize();
            x = Global.stage.stageWidth - 258;
            y = 160 + 20 * (Global.stage.stageHeight / 1000);
            this.updateJudgeRect();
            return;
        }// end function

        protected function updateJudgeRect() : void
        {
            this._judgeRec.x = this.x;
            this._judgeRec.y = this.y;
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show();
            this.stageResize();
            return;
        }// end function

        override public function get width() : Number
        {
            return 232;
        }// end function

        override public function refresh(param1:Boolean = false) : void
        {
            super.refresh(param1);
            if (!allowRefresh)
            {
                return;
            }
            if (this.contentPanel)
            {
                this.contentPanel.refresh(param1);
            }
            if (this.isClose)
            {
                this.close();
            }
            else
            {
                this.open();
            }
            return;
        }// end function

        protected function CreateBg() : Bitmap
        {
            return UIFactory.bitmap("TaskTrackBg", 0, 1, this._bgSprite);
        }// end function

    }
}
